<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions 
 * @package    Socialengineaddon
 * @copyright  Copyright 2009-2010 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: install.php (var) 2010-11-18 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */

class Socialengineaddon_Installer extends Engine_Package_Installer_Module {
	
	function onPreInstall() {
		parent::onPreInstall ();
	}
	
	function onInstall() {
		
		$db = $this->getDb ();
		
		$db->query ( 'CREATE TABLE IF NOT EXISTS `engine4_socialengineaddon_tabs` (
			`tab_id` int(11) NOT NULL AUTO_INCREMENT,
			`module` varchar(64) NOT NULL,
			`type` varchar(64) NOT NULL,
			`name` varchar(64) NOT NULL,
			`title` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
			`enabled` tinyint(1) NOT NULL DEFAULT "1",
			`order` int(3) NOT NULL DEFAULT "0",
			`limit` int(3) NOT NULL,
			PRIMARY KEY (`tab_id`),
			UNIQUE KEY `name` (`name`)
		) ENGINE = InnoDB AUTO_INCREMENT=1;' );
		
		$table_exist = $db->query ( 'SHOW TABLES LIKE \'engine4_socialengineaddons\'' )->fetch ();
		if (! empty ( $table_exist )) {
			$column_exist = $db->query ( 'SHOW COLUMNS FROM engine4_socialengineaddons LIKE \'is_activate\'' )->fetch ();
			if (empty ( $column_exist )) {
				$db->query ( "ALTER TABLE  `engine4_socialengineaddons` ADD  `is_activate` INT NOT NULL DEFAULT  '0'" );
			}
		}
		
		$table_exist = $db->query ( 'SHOW TABLES LIKE \'engine4_socialengineaddon_locations\'' )->fetch ();
		if (! empty ( $table_exist )) {
			$db->query ( "
			ALTER TABLE  `engine4_socialengineaddon_locations` CHANGE  `location`  `location` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL ,
			CHANGE  `formatted_address`  `formatted_address` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL ,
			CHANGE  `country`  `country` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL ,
			CHANGE  `state`  `state` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL ,
			CHANGE  `zipcode`  `zipcode` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL ,
			CHANGE  `city`  `city` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL ,
			CHANGE  `address`  `address` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL" );
		}
		
		parent::onInstall ();
	}
}
